﻿package mortal.game.view.common.guide.stepOperater
{
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.mvc.core.*;

    public class AutoGuideEventSteper extends Object implements IAutoGuideSteper
    {
        private var _data:AutoGuideData;

        public function AutoGuideEventSteper()
        {
            return;
        }// end function

        public function guide(param1:AutoGuideData, param2:Window = null) : void
        {
            var _loc_4:Object = null;
            this._data = param1;
            var _loc_3:* = param1.clickChildName as String;
            if (_loc_3 != null && _loc_3.indexOf("{") == 0)
            {
                _loc_4 = JSON.parse(_loc_3);
            }
            else if (_loc_3 != null && _loc_3.indexOf("int") >= 0)
            {
                _loc_4 = int(_loc_3.substr(3));
            }
            else
            {
                _loc_4 = _loc_3;
            }
            if (this._data.subType == AutoGuideActivedType.Sub_AddEventListener)
            {
                Dispatcher.addEventListener(param1.guideTypeValue as String, this.gotEventHandler);
            }
            else if (this._data.subType == AutoGuideActivedType.Sub_AddEventListener_Return)
            {
                Dispatcher.addEventListener(param1.guideTypeValue as String, this.gotEventHandler);
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStepEnd, param1));
            }
            else if (this._data.subType == AutoGuideActivedType.Sub_AddNetEventListener)
            {
                NetDispatcher.addCmdListener(param1.guideTypeValue as String, this.gotEventHandler);
            }
            else
            {
                Dispatcher.dispatchEvent(new DataEvent(param1.guideTypeValue as String, _loc_4));
                this.stop(this._data);
            }
            return;
        }// end function

        private function gotEventHandler(param1 = null) : void
        {
            this.stop(this._data);
            return;
        }// end function

        public function stop(param1:AutoGuideData = null) : void
        {
            if (this._data.subType == AutoGuideActivedType.Sub_AddEventListener)
            {
                Dispatcher.removeEventListener(this._data.guideTypeValue as String, this.gotEventHandler);
            }
            else if (this._data.subType == AutoGuideActivedType.Sub_AddNetEventListener)
            {
                NetDispatcher.removeCmdListener(param1.guideTypeValue as String, this.gotEventHandler);
            }
            if (param1 != null)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStepEnd, param1));
            }
            return;
        }// end function

    }
}
